home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 October
/
CHIP Turkiye Ekim 2000.iso
/
prog
/
naps
/
04
/
setup.exe
/
Gnucleus
/
PrefDialog.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-06-28
|
6KB
|
226 lines
/********************************************************************************
Gnucleus - A node application for the Gnutella network
Copyright (C) 2000 John Marshall
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For support, questions, comments, etc...
E-Mail:
swabby@c0re.net
Address:
21 Cadogan Way
Nashua, NH, USA 03062
********************************************************************************/
// PrefDialog.cpp : implementation file
//
#include "stdafx.h"
#include "Gnucleus.h"
#include "GnucleusDoc.h"
#include "PrefDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPrefDialog
IMPLEMENT_DYNAMIC(CPrefDialog, CPropertySheet)
CPrefDialog::CPrefDialog(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
}
CPrefDialog::CPrefDialog(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
AddPages();
}
CPrefDialog::~CPrefDialog()
{
((CGnucleusDoc *) ((CGnucleusApp *) AfxGetApp())->MasterDoc)->WriteINI();
}
void CPrefDialog::AddPages()
{
// Don't load the help button, maybe later we can put help in
m_hIcon = AfxGetApp()->LoadIcon(IDR_DEBUG);
m_psh.dwFlags |= PSP_USEHICON;
m_psh.hIcon = m_hIcon;
m_psh.dwFlags &= ~PSH_HASHELP;
// Add Tabs
AddPage(&m_TabConnect);
AddPage(&m_TabSearch);
AddPage(&m_TabDownload);
AddPage(&m_TabUpload);
AddPage(&m_TabBandwidth);
AddPage(&m_TabLanguage);
// Disable the tabs, so we can use the tree control.
//this->SetWizardMode();
}
BEGIN_MESSAGE_MAP(CPrefDialog, CPropertySheet)
//{{AFX_MSG_MAP(CPrefDialog)
ON_WM_CREATE()
//}}AFX_MSG_MAP
ON_NOTIFY(TVN_SELCHANGED, IDC_PREF_TREE, OnSelchanged)
ON_MESSAGE(WM_NOTIFYFORMAT, OnNotifyFormat)
ON_COMMAND(ID_APPLY_NOW, OnApplyNow)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPrefDialog message handlers
BOOL CPrefDialog::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
// Disable the tabs, so we can use the tree control.
GetTabControl()->ShowWindow(SW_HIDE);
// Setup the tree control dynamicly
CRect rectWnd, rectTree;
GetWindowRect(rectWnd);
ScreenToClient(rectWnd);
rectTree.SetRect(PREF_TREE_MARGIN_LEFT, PREF_TREE_MARGIN_TOP,
PREF_TREE_MARGIN_LEFT + PREF_TREE_WIDTH, rectWnd.bottom - PREF_TREE_MARGIN_BOTTOM );
BOOL bCreateResult = m_Tree.Create( WS_VISIBLE | WS_TABSTOP | WS_CHILD | WS_BORDER |
TVS_LINESATROOT | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS,
rectTree, this , IDC_PREF_TREE);
// m_Tree.ModifyStyleEx(0, WS_EX_WINDOWEDGE);
// Flesh out the tree control.
m_Tree.SelectItem(m_Tree.InsertItem("Connect")); // select the first item
m_Tree.InsertItem("Search");
m_Tree.InsertItem("Download");
m_Tree.InsertItem("Share");
m_Tree.InsertItem("Bandwidth");
m_Tree.InsertItem("Language");
//save rect for property pages
GetActivePage()->GetWindowRect(m_rectPage);
ScreenToClient(m_rectPage);
return bResult;
}
int CPrefDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CPropertySheet::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rectWnd;
GetWindowRect(rectWnd);
// add space for the tree control to the width of the dialog box.
rectWnd.right += PREF_TREE_WIDTH + PREF_TREE_MARGIN_LEFT + PREF_TREE_MARGIN_RIGHT;
MoveWindow(rectWnd);
CenterWindow(NULL);
return 0;
}
////////////////////////////////////////////////////////////
//! author="Nathan Brown"
//
// Switches property sheets on selection of item in the tree view
void CPrefDialog::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
*pResult = 0;
HTREEITEM htItem = m_Tree.GetSelectedItem();
if(htItem != NULL)
{
CString str_item_text = m_Tree.GetItemText(htItem);
if( str_item_text == "Connect")
SetActivePage(&m_TabConnect);
else if( str_item_text == "Search")
SetActivePage(&m_TabSearch);
else if( str_item_text == "Download")
SetActivePage(&m_TabDownload);
else if( str_item_text == "Share")
SetActivePage(&m_TabUpload);
else if( str_item_text == "Bandwidth")
SetActivePage(&m_TabBandwidth);
else if( str_item_text == "Language")
SetActivePage(&m_TabLanguage);
// Set the title
SetTitle((LPCTSTR)str_item_text, PSH_PROPTITLE);
}
CRect rectWnd;
// Move window around because of tree control and no tabs.
GetActivePage()->GetWindowRect(rectWnd);
ScreenToClient(rectWnd);
// move over and up
rectWnd.OffsetRect( PREF_TREE_MARGIN_LEFT + PREF_TREE_WIDTH + PREF_TREE_MARGIN_RIGHT,
-PREF_TAB_OFFSET_UP);
GetActivePage()->MoveWindow(rectWnd);
}
////////////////////////////////////////////////////////////
//! author="Nathan Brown"
//
// Fix for confirmed bug in NT (Q148533) for control using
// UNICODE messages when it shouldn't.
LRESULT CPrefDialog::OnNotifyFormat(WPARAM wParam, LPARAM lParam)
{
#ifdef _UNICODE
return NFR_UNICODE;
#else
return NFR_ANSI;
#endif
}
////////////////////////////////////////////////////////////
//! author="Nathan Brown"
//
// Intercep the Apply Now command, and correct the positioning.
void CPrefDialog::OnApplyNow()
{
Default();
GetActivePage()->MoveWindow(m_rectPage);
}